<?php if (!defined('THINK_PATH')) exit();?><!-- 会话列表 -->
<?php $rand = round(microtime(true),3)*1000;?>
<table id="sessionList_<?php echo ($rand); ?>" class="easyui-datagrid" title="<?php echo ($currentpos); ?>" data-options="
	fit:true,rownumbers:true,animate:true,fitColumns:true,
	url:'<?php echo U('session/push',array('uid'=>I('id',0)));?>',idField:'id',border:false,
	toolbar:'#sessionToolbar_<?php echo ($rand); ?>',pagination:true,singleSelect:true,pageSize:20,nowrap:false">
    <thead>

    <!--<a href="javascript:void(0);" onclick="incScore('+val+')">增值</a>-->

    <tr>
        <th data-options="field:'keywords',width:1,align:'left'">关键字</th>
        <th data-options="field:'create_time',width:1">创建时间</th>
        <th data-options="field:'id',width:10,formatter:sessionOperateText">操作</th>
    </tr>
    </thead>
</table>

<div id="sessionToolbar_<?php echo ($rand); ?>" style="padding:5px;height:auto">
    <form id="sessionSearchForm_<?php echo ($rand); ?>">
        <a href="javascript:;" onclick="sessionRefreshList_<?php echo ($rand); ?>();" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
        <a href="javascript:;" onclick="incKeywords()" class="easyui-linkbutton" iconCls="icon-add">添加</a>
    </form>
</div>





<!-- 编辑 -->
<div id="sessionEditBox" class="easyui-dialog" title="编辑会话"
     data-options="modal:true,closed:true,iconCls:'icon-add',
				buttons:[{text:'确定',iconCls:'icon-ok',
				handler:function(){$('#sessionEditForm').submit();}},
				{text:'取消',iconCls:'icon-cancel',
				handler:function(){$('#sessionEditBox').dialog('close');}}]"
     style="width: 600px; height: 280px;"></div>


<div id="pushEditBox" class="easyui-dialog" title="编辑会话推送"
     data-options="modal:true,closed:true,iconCls:'icon-add',
				buttons:[{text:'确定',iconCls:'icon-ok',
				handler:function(){$('#pushConfigEditForm').submit();}},
				{text:'取消',iconCls:'icon-cancel',
				handler:function(){$('#pushEditBox').dialog('close');}}]"
     style="width: 600px; height: 280px;"></div>

<script type="text/javascript">
    function incKeywords(){
        $.messager.prompt('提示信息', '请输入你要增加关键字', function(keywords){
            console.log(keywords);
            if(!keywords) return false;

            $.post('<?php echo U('session/addPush');?>', { keywords: keywords }, function(data){
                if(!data.status){
                    $.messager.alert('提示信息', data.info, 'error');
                }else{
                    sessionRefreshList_<?php echo ($rand); ?>();
                    $.messager.alert('提示信息', data.info, 'info');
                }
            }, 'json');
        });
    }
    //刷新
    function sessionRefreshList_<?php echo ($rand); ?>(){
        $('#sessionList_<?php echo ($rand); ?>').datagrid('reload');
    }
    //logo显示
    function buildFace(val,row,index){
        if(!val){
            return '<div style="height:60px;padding:3px;margin:auto;"></div>';
        }else{
            return '<img src="'+val+'" height="60" style="padding:3px;">';
        }
    }
    //操作格式化
    function sessionOperateText(val, row, index){
        var btn = [];
        btn.push('<a href="javascript:void(0);" onclick="sessionDelete('+val+')">删除</a>');
//		btn.push('<a href="javascript:void(0);" onclick="pushConfig('+val+','+row.uid+')">设置推送</a>');
        return btn.join(' | ');
    }
    //会话删除
    function sessionDelete(id){
        if(typeof(id) !== 'number'){
            $.messager.alert('提示信息', '未选择', 'error');
            return false;
        }
        $.messager.confirm('提示信息', '确定要删除吗？', function(result){
            if(!result) return false;
            $.post('<?php echo U('session/deletePush');?>', {id: id}, function(data){
                if(!data.status){
                    $.messager.alert('提示信息', data.info, 'error');
                }else{
                    sessionRefreshList_<?php echo ($rand); ?>();
                    $.messager.alert('提示信息', data.info, 'info');
                }
            }, 'json');
        });
    }
</script>